package com.itsitio.registeradmin.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;


@Entity
@Table(name = "portales")
public class Portal {
//public class Company extends MappedEntity{

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name = "idx")
	private Integer id;
	
	//Nombre del Portal
	@Column(name = "descripcion", length = 200)
	private String name;

	/*
	@ManyToOne(cascade = CascadeType.MERGE)
	@JoinColumn(name="idxpais")
	Country country;
	*/	
	

	//@ManyToMany(cascade = CascadeType.PERSIST)
	/*
	@ManyToMany(fetch = FetchType.EAGER)	
    @JoinTable(name = "xxxportalesXcomunidadesXpaises",
        joinColumns = {@JoinColumn(name = "IdxPortal")},
        inverseJoinColumns = {@JoinColumn(name = "IdxPais")})
    */
	//@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, mappedBy = "portals", targetEntity = com.itsitio.registeradmin.model.Country.class)

	//targetEntity=com.itsitio.registeradmin.model.Country.class,
	@ManyToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE})	
    @JoinTable(name = "portalesXcomunidadesXpaises",
        joinColumns = {@JoinColumn(name = "IdxPortal")},
        inverseJoinColumns = {@JoinColumn(name = "IdxPais")})
	private List<Country> countries;

	//Status del Portal, si esta activo o no
	@Column(name = "status")//, nullable = false)
	private Byte active;
		
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/*
	public Country getCountry() {
		return country;
	}

	public void setCountry(Country country) {
		country = country;
	}
	*/

	public List<Country> getCountries() {
		return countries;
	}

	public void setCountries(List<Country> countries) {
		this.countries = countries;
	}
	
	public Byte getActive() {
		return active;
	}

	public void setActive(Byte active) {
		this.active = active;
	}
	
  @Override
    public boolean equals(Object o) {
        if(o == null || !(o instanceof Portal))
            return false;

        Portal portal = (Portal) o;

        return this.getId().equals(portal.getId())
                && this.getName().equals(portal.getName());
    }

}
